package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketGoodsExample;
import com.cskaoyan.market.db.domain.MarketGoodsProductExample;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsProductMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.service.AdminDashBoardService;
import com.cskaoyan.market.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA 2021.
 * User: Lazarus_Liu
 * Date: 2023/7/24
 * Time: 22:44
 * Description:
 */
public class AdminDashBoardServiceImpl implements AdminDashBoardService {
    @Override
    public Map<String, Long> getData() {
        // 从数据库中查询数据
        // 1. goodsTotal
        // 2. userTotal
        // 3. productTotal
        // 4. orderTotal

        // 获取SqlSession
        SqlSession session = MybatisUtil.getSession();

        // 1---goodsTotal
        MarketGoodsMapper goodsMapper = session.getMapper(MarketGoodsMapper.class);
        long goodsTotal = goodsMapper.countByExample(new MarketGoodsExample());


        // 2---userTotal
        MarketUserMapper userMapper = session.getMapper(MarketUserMapper.class);
        // 获取全量数据
        long userTotal = userMapper.countByExample(new MarketUserExample());

        // 3---productTotal
        MarketGoodsProductMapper productMapper = session.getMapper(MarketGoodsProductMapper.class);
        long productTotal = productMapper.countByExample(new MarketGoodsProductExample());

        // 4---orderTotal
        MarketOrderMapper orderMapper = session.getMapper(MarketOrderMapper.class);
        long orderTotal = orderMapper.countByExample(new MarketOrderExample());



        // 返回map给Controller
        HashMap<String, Long> data = new HashMap<>();
        data.put("goodsTotal", goodsTotal);
        data.put("userTotal", userTotal);
        data.put("productTotal", productTotal);
        data.put("orderTotal", orderTotal);
        return data;

    }
}
